package tr.edu.ege.communicator.util;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 
 * A logger implementation that logs the desired text. This class can be
 * customized for different logging types.
 * 
 * @author Onur ULUSU
 * 
 */
public class CommunicatorLogger {

	/**
	 * Writes the given string to the console as a log. <br>
	 * <br>
	 * <blockquote>
	 * Examples of usage: <br>
	 * <li><code> CommunicatorLogger.log("Port %d is in use..", PORT_NUMBER);</code>
	 * <li><code> CommunicatorLogger.log("Port 5555 is in use..");</code>
	 * 
	 * @param logString
	 *            the string to be logged
	 * @param args
	 */
	public static void log(String logString, Object... args) {
		try {
			// creating new logger..
			Logger logger = Logger.getAnonymousLogger();
			String logRecord = String.format(logString, args);
			// publishing the log..
			logger.log(Level.INFO, logRecord);
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("Logging error! Invalid log format..");
		}
	}
}
